#include<cstdio>
#include<cstring>
#include<vector>
using std::vector;
const int maxn=100010;
long long f[maxn],ans;
int p[maxn],n,v[maxn];
bool vis[maxn];
vector<int> son[maxn];
long long min(long long x,long long y){return x<y?x:y;}
long long max(long long x,long long y){return x>y?x:y;}
long long abs(long long x)
{
	if(x<0)return x*-1;
	return x;
}
void dfs(int root)
{
	vis[root]=1;
	f[root]=v[root];
	for(int i=0;i<son[root].size();i++)
	{
		if(vis[son[root][i]])continue;
		dfs(son[root][i]);
		f[root]+=f[son[root][i]];
	}	
}
int main()
{
	int t=0,m;
	while(scanf("%d%d",&n,&m)&&(n+m!=0)){
	t++;
	memset(p,0,sizeof(p));
	memset(f,0,sizeof(f));
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=n;i++)scanf("%d",&v[i]);
	for(int i=0;i<=n;i++)
		son[i].clear();	
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		son[x].push_back(y);
		son[y].push_back(x);
	}
	dfs(1);
	long long amin=f[1];
	for(int i=2;i<=n;i++)
	{
		ans=abs(f[1]-f[i]*2);
		if(ans<amin)
		{
			amin=ans;
		}
	}
	printf("Case %d: %lld\n",t,amin);}
	return 0;
}

